package com.sky.config;

import com.sky.properties.AliOssProperties;
import com.sky.utils.AliOssUtil;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 自动配置类
 */
@Configuration
@EnableConfigurationProperties(AliOssProperties.class)// 将这个类导入到ioc容器中成为bean
public class OssConfiguration {

    @Bean
    @ConditionalOnMissingBean // 没有这个bean时再创建
    public AliOssUtil aliOSSUtils(AliOssProperties aliOSSProperties) {
        //自动创建AliOssUtil 工具类
        AliOssUtil aliOSSUtils = new AliOssUtil(
                aliOSSProperties.getEndpoint(),
                aliOSSProperties.getAccessKeyId(),
                aliOSSProperties.getAccessKeySecret(),
                aliOSSProperties.getBucketName());

        return aliOSSUtils;
    }
}
